home *** CD-ROM | disk | FTP | other *** search
- vsyncon=0 ;switch on if you want vsync (no tearing visible)
- #scrolling=0 ;set to 1 if you check speed when you scroll the background
- optimize 7;
-
- ;Statement error {_text.s} ; enable this statement if you don't have error.include !
- ;SHARED image_errcnt.l
- ;If image_errcnt Then Statement Return
- ;image_errcnt+1
- ;n.l = Request("ERROR:",_text.s,"OK")
- ;End Statement
- ;
- ;A little demo of moving things using the Blit command...
- ; the image.res must inlcude in compileroptions to use this functions
- WBStartup
- ;create a 'ball' type variable
- ;
- NEWTYPE.ball
- x.q
- y
- xs
- ys
- End NEWTYPE
- DEFTYPE.l
- ;dimension a 'List' of 'balls'
- Dim List balls.ball(50)
- !image_include:
-
- ;a beginning of directblit ignore it ***********************************
- ;@@1
- Macro image_blitmask2 ;{image,x,y,mode} if mode=1 blit non rectangle objects
- Statement image_blitmask2{image.l,x.l,y.l,mode.l}
- SHARED imagedat(),imgtags()
- USEPATH imagedat(image)
- If \bitmap_ptr=0 ;initialize all
- If \pic_ptr
- *win._Window = Peek.l(Addr Window(Used Window))
- If *win=0 Then error {"Tried to blit into a non-existing window !"}:Statement Return
- *scr._Screen = Peek.l(Addr Screen(Used Screen))
- If *scr=0 Then error{"Tried to blit into a non-exisiting screen !"}:Statement Return
- If \drawhandle Then ReleaseDrawHandle_ \drawhandle : \drawhandle = False
- ;*vp._ViewPort = ViewPort(Used Screen)
- \drawhandle = ObtainDrawHandleA_ (\psm_ptr,RastPort(Used Window),*scr\_ViewPort\ColorMap, #TAG_DONE)
- If \drawhandle=0 Then error{"No draw handle"}:Statement Return
- If DoPictureMethodA_(\pic_ptr,#PICMTHD_CREATEALPHAMASK,0)=0
- error {"Cannot create alpha mask (work only on 24bit image) !"}
- Statement Return
- End If
- width.l=((\img_width+15)LSR 4)ASL 1
- \mask_ptr=AllocMem((width*\img_height)+32,$10000)
- size.l=width*\img_height
- If \mask_ptr=0 Then error{"Cannot find MaskMem !"}:Statement Return
- If CreatePictureMaskA_(\pic_ptr,\mask_ptr,width,Tags(@@
- #GGFX_Ratio,2))=0
- error {"Cannot create Mask !"}
- Statement Return
- End If
- \bitmap_ptr=CreatePictureBitMapA_(\drawhandle,\pic_ptr,0)
- Else
- error {"Uninitialisized image/window/screen !"}
- End If
- End If
- If Peek.l(Addr Window(Used Window))
-
- w=\img_width
- h=\img_height
- If x>799 Then Statement Return
- If y>599 Then Statement Return
- If w+x>799 Then w=799-x
- If h+y>599 Then h=599-y
- If w<=0 Then Statement Return
- If h<=0 Then Statement Return
- m.l=\mask_ptr
- *srcbm._BitMap=\bitmap_ptr
- *dstbm._BitMap=Peek.l(RastPort(Used Window)+4)
- d.l=*dstbm._BitMap\Planes
- s.l=*srcbm._BitMap\Planes
- d=*dstbm._BitMap\BytesPerRow*y+d+x*2
- width.l=((\img_width+15)LSR 4)ASL 1
- For i=1 To h
- GetD0 w:MOVE.l d0,d1
- GetD0 s:MOVE.l d0,a0
- GetD0 d:MOVE.l d0,a1
- GetD0 m:MOVE.l d0,a2
- MOVEQ #31,d3
- MOVE.l (a2)+,d2
- label`@
- BTST.l d3,d2
- BEQ l2`@
- MOVE.w (a0),(a1)
- l2`@ ADDQ.l #2,a0
- ADDQ.l #2,a1
- SUBQ.l #1,d3
- BGE l5`@
- MOVE.l (a2)+,d2
- MOVEQ #31,d3
- l5`@
- DBF d1,label`@
- ;For i2=1 To w Step 2
- ;Poke.w d+i2,Peek.w (s+i2)
- ; Next
- s+*srcbm._BitMap\BytesPerRow
- d+*dstbm._BitMap\BytesPerRow
- m+width
- Next
- ;BltMaskBitMapRastPort_ \bitmap_ptr,0,0,RastPort(Used Window),x,y,\img_width,\img_height,$c0,\mask_ptr
- Else
- error {"Tried to blit into a non-existing window "}
- End If
- End Statement
- End Macro
- ;@@0
- ;************************************* end of not used
- !image_blitmask2:
-
- !screen_ {0,"","ram:prefsfile",1}:If !screen_id=0 Then End ;for display
- width=!screen_width
- height=!screen_height
- Window 0,0,0,width,height,$800,"",0,1
- succ=image_load {1,"amiga1000.jpg"}
- succ=image_load {0,"ball.iff"}
- image_blit{1,0,0} ;to set the palette for 8bit screens
- InitShape 0,16,16,2
- WPointer 0 ;set a unvisible mousepointer
- !screen_ {1,"","ram:prefsfile",0}:If !screen_id=0 Then End ;for render
- ;a second screen for doublebuffer
- Window 1,0,0,width,height,$800,"",0,1 ;second window
- !screen_ {2,"","ram:prefsfile",0}:If !screen_id=0 Then End ;screen for background
-
- Window 2,0,0,width,height,$800,"",0,1 ;window to store backgroundimage
- image_blit{1,0,0} ;blit the backgroundimage in window
- ;keep adding items to list until list full
- ;
- While AddLast(balls())
- balls()\x=Rnd(width-30)+15,Rnd(height-30)+15,(Rnd-.5)*20+1,(Rnd-.5)*20+1
- ;balls()\x=20,10,1,1
- Wend
-
- ShowScreen 0
- ;while mouse button not hit..
- ;
- While Joyb(0)=0
-
- If vsyncon VWait ;can enable if you dont like tearing
- ;but most time this is unvisibly
- Use Screen 1 ;copy all from screen 1 to window 0
- Use Window 0
- image_blitblock{0,0,0,0,0,0}
- CNIF #scrolling>0
- Use Window 2
- WScroll 0,0,width,height,1,1 ;scroll the background
- CEND
- Use Window 1 ;set the renderwindow to 1
- ;start at first item in list
- ;
- ResetList balls()
- ;WCls
- Use Screen 2 ;use the backgroundimage from screen 2
- ;screennum is source
- ;windowsnum is destination
- image_blitblock {0,0,0,0,0,0} ;blit whole backgroundimage
- WLocate 220,55
- If res<5 Then res=5
- CNIF #scrolling=0 ;use textbackgroundcolor when scroll to read fps better
- WJam 0 ;dont use textbackgroundcolor
- CEND
- NPrint "fps ",50/(res LSR 2)," ",num
- ;wait for vertical blank
- ;
- ;Delay_(1)
-
- ;while more items to come...
- ;
- While NextItem(balls())
- balls()\x+balls()\xs
- balls()\y+balls()\ys
- ;reverse direction if ball gets to edge of bitmap
- ;
- If balls()\x<10 OR balls()\x>width Then balls()\xs=-balls()\xs
- If balls()\y<10 OR balls()\y>height Then balls()\ys=-balls()\ys
- image_blitmask{0,balls()\x,balls()\y,1} ;draw balls
- 'l1 BTST #6,$dff016
- BEQ 'l1
- Wend
- count+1
- If count=4 Then count=0:res=Timer:ResetTimer
- Wend
- End ;important allow autofree
-